package net.tngou.iask.action.api;

import net.tngou.iask.action.BaseAction;
import net.tngou.iask.pojo.Memo;

/**
 * 评论
 * @author tngou@tngou.net
 *
 */
public class MemoApi extends BaseAction {

	
	/**
	 * 添加消息
	 */
	public void add() {
		if(user==null){
			run_nologin();return;
		}
		Memo bean = getAsk(Memo.class);
		if(isEmpty(bean.getMsgs(),bean.getOid(),bean.getOtype()))
		{
			run_false("请求的参数不正确！");return;
		}
		bean.setUser(user.getId());
		long id = bean.save();
		if(id>0){
			run_success(id+"");
		}else
		{
			run_success("添加失败！");
		}
		
	}
	
	/**
	 * 删除消息
	 */
	public void delete() {
		if(user==null){
			run_nologin();return;
		}
		if(ask.getId()==0)
		{
			run_false("请求的参数不正确！");return;
		}
		Memo memo = new Memo().get(ask.getId());
		if(memo==null||memo.getUser()!=user.getId())
		{
			run_false("请求的数据不正确！");return;
		}
		boolean b = memo.delete();
		if(b){
			run_success("删除成功！");
		}else
		{
			run_success("删除失败！");
		}
	}
}
